<template>
  <!-- 查看详情 2018/3/7 11:44 zhangQ -->
  <div>

    <tablePage ref="subOrderTab" :staticData="subOrderData" :isStartLoad="false" :mode="1">
      <template slot-scope="props">
        <Table :columns="subOrderColumn" border :data="props.data" @on-sort-change="props.sortChange"></Table>
      </template>
    </tablePage>

    <xlinkModal v-model="ImgModel" title="图片" className="vertical-center-modal" width="700px;">
      <viewMedia :lookImtList="lookImtList" v-if="ImgModel"></viewMedia>
    </xlinkModal>
  </div>
</template>

<script>
  import {findDetailListByFleetOrderNo} from '@api/backEnd/fleetOrder/index'
  import xlinkModal from '@components/modal/xlinkModal'
  import viewMedia from './viewMedia'
  import tablePage from '@components/table/tablePage.vue'
  import {getTrainTypeCN} from './fleetDispatch1/components/trainTypeEnum'

  export default {
    name: 'view-fleet-order-detail',
    data () {
      let subOrderColumn = [
        {
          title: '子运单单号',
          ellipsis: 'true',
          key: 'subOrderId',
          width: 200
        },
        {
          title: '火车车种类型',
          ellipsis: 'true',
          width: 150,
          render: (h, params) => {
            let trainType = params.row.trainType
            let trainTypeCN = getTrainTypeCN(trainType)
            return (<span>{trainTypeCN}</span>)
          }
        },
        {
          title: '箱号',
          ellipsis: 'true',
          width: 150,
          key: 'containerNo'
        },
        {
          title: '发货人',
          ellipsis: 'true',
          key: 'receiver',
          width: 250
        },
        {
          title: '收货人',
          ellipsis: 'true',
          key: 'shipper',
          width: 250
        },
        {
          title: '司机',
          ellipsis: 'true',
          key: 'driverId',
          width: 200,
          render: (h, params) => {
            return (<span>{params.row.driverName}</span>)
          }
        },
        {
          title: '送货地址',
          ellipsis: 'true',
          width: 200,
          key: 'outAddress'
        },
        {
          title: '联系人',
          ellipsis: 'true',
          width: 100,
          key: 'outContacts'
        },
        {
          title: '联系人电话',
          ellipsis: 'true',
          width: 150,
          key: 'outMobile'
        },
        {
          title: '品名',
          ellipsis: 'true',
          key: 'pm',
          width: 150
        },
        {
          title: '接取费(元)',
          ellipsis: 'true',
          key: 'receiveFee',
          width: 120
        },
        {
          title: '送达费(元)',
          ellipsis: 'true',
          key: 'deliverFee',
          width: 120
        },
        {
          title: '状态',
          ellipsis: 'true',
          width: 100,
          key: 'state',
          render: (h, params) => {
            let state = params.row.state
            if (state === 5) {
              return (<span>已完成</span>)
            } else if (state === 4) {
              return (<span style="color:green">配送中</span>)
            } else if (state === 2 || state === 3) {
              return (<span style="color:green">已派单</span>)
            } else if (!state === 1) {
              return (<span style="color:red">待配送</span>)
            } else {
              return ''
            }
          }
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          width: 100,
          render: (h, params) => {
            let viewImg = ''
            if (params.row.voucherImg && JSON.parse(params.row.voucherImg).length > 0) {
              viewImg = (<i-button type="primary" size="small" style="margin-right: 5px;" onClick={() => this.viewDetailImg(params.row)}>图片查看</i-button>)
            } else {
              viewImg = (<i-button size="small" style="margin-right: 5px;">图片查看</i-button>)
            }
            let btnArray = []
            powerUtil.contains('viewDetail') && btnArray.push(viewImg)
            return (btnArray)
          }
        }
      ]
      let subOrderData = []
      let positionList = []
      let ImgModel = false
      let lookImtList = []
      let datas = {
        subOrderColumn,
        subOrderData,
        positionList,
        ImgModel,
        lookImtList
      }
      return datas
    },
    props: {
      currentMainOrder: {
        type: Object,
        default () {
          return {}
        }
      }
    },
    computed: {},
    methods: {
      getSubOrderData () {
        console.log(this.currentMainOrder)
        if (!(this.currentMainOrder && this.currentMainOrder.id)) {
          return
        }
        let param = {
          fleetMainOrderNo: this.currentMainOrder.id
        }
        findDetailListByFleetOrderNo(param).then(res => {
          if (res.data.isSuccess === 1) {
            this.subOrderData = res.data.data
          } else {
            Promise.reject(new Error(res.data.res))
          }
        }).catch((err) => {
          console.log('接口getOrderDetail:' + err)
        })
      },
      viewDetailImg (row) {
        console.log('viewDetailImg', row.voucherImg)
        this.lookImtList = JSON.parse(row.voucherImg)
        this.ImgModel = true
      }
    },
    mounted () {
      this.getSubOrderData()
    },
    components: {tablePage, xlinkModal, viewMedia}
  }
</script>
